﻿using NPOI.SS.UserModel;
using System.Text;

namespace NpoiSample.Helper.CompleteCustomer.Dto
{
    /// <summary>
    /// 单元格样式
    /// </summary>
    public class BaseCellStyle
    {
        /// <summary>
        /// 单元格样式
        /// </summary>
        /// <param name="isBold">是否粗体</param>
        /// <param name="fontName">字体</param>
        /// <param name="fontSize">文字大小</param>
        /// <param name="horizontal">水平对齐</param>
        /// <param name="vertical">垂直对齐</param>
        /// <param name="wrapText">是否换行</param>
        /// <param name="borderBottom">下边框</param>
        /// <param name="borderLeft">左边框</param>
        /// <param name="borderRight">右边框</param>
        /// <param name="borderTop">头部边框</param>
        /// <param name="showAllBorder">是否显示所有边框</param>
        /// <param name="bottomBorderColor">下边框颜色</param>
        /// <param name="leftBorderColor">左边框颜色</param>
        /// <param name="rightBorderColor">右边框颜色</param>
        /// <param name="topBorderColor">头部边框颜色</param>
        /// <param name="fillForegroundColor">单元格背景色</param>
        public BaseCellStyle(bool isBold = false, string fontName = "微软雅黑", double fontSize = 12, HorizontalAlignment horizontal = HorizontalAlignment.Center,
            VerticalAlignment vertical = VerticalAlignment.None, bool wrapText = false, BorderStyle borderBottom = default, BorderStyle borderLeft = BorderStyle.None,
            BorderStyle borderRight = BorderStyle.None, BorderStyle borderTop = BorderStyle.None, bool showAllBorder = false, short bottomBorderColor = 8, short leftBorderColor = 8,
            short rightBorderColor = 8, short topBorderColor = 8, short? fillForegroundColor = null)
        {
            IsBold = isBold;
            FontName = fontName;
            FontSize = fontSize;
            Alignment = horizontal;
            VerticalAlignment = vertical;
            WrapText = wrapText;
            BorderBottom = borderBottom;
            BorderLeft = borderLeft;
            BorderRight = borderRight;
            BorderTop = borderTop;
            BottomBorderColor = bottomBorderColor;
            LeftBorderColor = leftBorderColor;
            RightBorderColor = rightBorderColor;
            TopBorderColor = topBorderColor;
            FillForegroundColor = fillForegroundColor;

            if (showAllBorder)
            {
                BorderBottom = BorderStyle.Thin;
                BorderLeft = BorderStyle.Thin;
                BorderRight = BorderStyle.Thin;
                BorderTop = BorderStyle.Thin;
            }
        }

        public bool IsBold { get; }

        public string FontName { get; }

        public double FontSize { get; } = 12;

        /// <summary>
        /// 水平对其
        /// </summary>
        public HorizontalAlignment Alignment { get; set; } = HorizontalAlignment.Center;

        /// <summary>
        /// 垂直对齐
        /// </summary>
        public VerticalAlignment VerticalAlignment { get; set; } = VerticalAlignment.Center;

        /// <summary>
        /// 是否换行
        /// </summary>
        public bool WrapText { get; set; } = false;

        public short FontColor { get; set; } = 8;

        public BorderStyle BorderBottom { get; set; }
        public BorderStyle BorderLeft { get; set; }
        public BorderStyle BorderRight { get; set; }
        public BorderStyle BorderTop { get; set; }

        public short BottomBorderColor { get; set; }

        public short LeftBorderColor { get; set; }

        public short RightBorderColor { get; set; }

        public short TopBorderColor { get; set; }

        public short? FillForegroundColor { get; set; }

        public override string ToString()
        {
            var str = new StringBuilder();
            foreach (var item in GetType().GetProperties())
            {
                str.Append(item.Name).Append('_').Append(item.GetValue(this)?.ToString() ?? string.Empty).Append("__");
            }

            return str.ToString();
        }
    }
}